package com.ihmp.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ihmp.model.Trooms;
import com.ihmp.model.Troomtypes;
import com.ihmp.model.User;
@Repository("RoomsDao")
public class RoomsDaoImpl  implements RoomsDao{

	@Autowired
	private SessionFactory sessionFactory;

	
	@Override
	public void save(Trooms room) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().save(room);
	}

	@Override
	public void update(Trooms room) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().update(room);
	}

	@Override
	public void delete(Integer id) {
		// TODO Auto-generated method stub
		Trooms room = (Trooms)sessionFactory.getCurrentSession().load(Trooms.class, id);
		if(null != room) sessionFactory.getCurrentSession().delete(room);
	}

	@Override
	public List<Trooms> listRooms() {
		// TODO Auto-generated method stub
		return sessionFactory.getCurrentSession().createQuery("from trooms").list();
		
	}

	@Override
	public List<Trooms> getRoomsFromHotel(Integer hotelId) {
		String strQuery = "from Trooms WHERE HotelID =:HotelID ";
		Query query = sessionFactory.getCurrentSession().createQuery(strQuery);
		query.setParameter("HotelID", hotelId);
		return query.list();
	}

	@Override
	public List<Troomtypes> getAllRoomsTypeFromHotel(Integer hotelId) {
		String strQuery = "from Trooms WHERE HotelID =:HotelID GROUP BY RoomTypeID ";
		Query query = sessionFactory.getCurrentSession().createQuery(strQuery);
		query.setParameter("HotelID", hotelId);
		return query.list();
	}

}
